﻿using System;
using SchemaGen.Xsd;

namespace SchemaGen.Attributes
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public sealed class XmlElementAttribute : XmlEntityBaseAttribute
    {
        public int MinOccurs { get; set; }
        
        /// <summary>
        /// Only applies when it's inside a Sequence. Set to negative or int.MaxValue to make it unbounded.
        /// </summary>
        public int MaxOccurs { get; set; }

        private string _NamedType;
        /// <summary>
        /// Use this or Type to set a type. They cannot both be set, one or neither may be set.
        /// </summary>
        public string NamedType
        {
            get { return _NamedType; }
            set
            {
                TypeName = value;
                _NamedType = value;
            }
        }

        /// <summary>
        /// If this element is going to contain other elements, it can have a sequence indicator.
        /// If it has no children, this parameter is ignored. Default sequence is "All".
        /// </summary>
        public SequenceIndicator SequenceIndicator { get; set; }

        public XmlElementAttribute(params string[] nameSegments)
            : base(nameSegments)
        {
            MinOccurs = 1;
            MaxOccurs = 1;
            SequenceIndicator = SequenceIndicator.Sequence;
        }
    }
}
